<?php

class ObjectRouteCredentialParser extends AbstractCredentialParser
{

  public function parse ($credential)
  {
    if ($this->hasOption('object_method'))
    {
      return $this->parseObjectMethod($credential);
    }
    
    return $credential;
  }

  protected function parseObjectMethod ($credential)
  {
    $method = $this->getOption('object_method');
    $result = $this->executeMethodChain($this->getActions()->getRoute(), $method);
    sfContext::getInstance()->getLogger()->err(print_r($credential, true));
    if (! is_array($result) && !is_object($result))
    {
      $result = array(
        $result);
    }
    
    $return = array();
    foreach($result as $item) {
      $return[] = sprintf($credential, $item);
    }
    
    return $return;
  }

  protected function getRouteObject ()
  {
    return $this->getActions()
      ->getRoute()
      ->getObject();
  }
}